<?php
session_start();
include('/config.inc.php');
include('/function/runid.php');
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">";
$day_in = $Current_date;
$no = getDetailNo();


$sumold = $sumDB-1;
	if($detail_no_format == 1){
		$DByear = "year";
	}else if($detail_no_format == 2){
		$DByear = "year_thai";
	}
//ดึงจากฐานข้อมูลแแล้วตัดข้อความ เก็บใส่ตัวแปลแล้วบวกค่าเพิ่ม
foreach($_POST[type] as $value){
		if($value!=null)continus;
		$fault = $value;
}
$fault_type = $fault;
$location_id = $_POST['location'];
$problem=$_POST['problem'];
$usernote = $_SESSION[user];
echo $usernote;
$sql = "insert into detail(day_in,no,fault_type,location_id,problem,username_note,status,complete) values('$day_in', '$no', '$fault', '$location', '$problem', '$usernote', '1','0')";
$result = mysql_query($sql);
if($result){
	$sumSql = "update sumfault set sum=$sumDB where sum=$sumold AND $DByear=$year";
	$sumResult = mysql_query($sumSql);
	$msg = ($sumResult)?"อัพเดทตัวนับแล้ว":"ไม่สามารถอัพเดทตัวนับได้";
	echo $msg;
	$DBno = getDbNo();
	echo sendMailFault($DBno);
	//echo "<meta http-equiv='refresh' content='0;URL=showfaultdetail.php?no=$DBno&process=golfsoccer'>";
}else{
	echo "ไม่สามารถเพิ่มข้อมูลลงฐานข้อมูลได้";
}
?>